/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package it.polimi.wcalendar.business.security.entity;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author gugu
 */
@Entity
@Table(name = "people_invited")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "PeopleInvited.findAll", query = "SELECT p FROM PeopleInvited p"),
    @NamedQuery(name = "PeopleInvited.findByIdusr", query = "SELECT p FROM PeopleInvited p WHERE p.peopleInvitedPK.idusr = :idusr"),
    @NamedQuery(name = "PeopleInvited.findByIde", query = "SELECT p FROM PeopleInvited p WHERE p.peopleInvitedPK.ide = :ide"),
    @NamedQuery(name = "PeopleInvited.findByAnswer", query = "SELECT p FROM PeopleInvited p WHERE p.answer = :answer")})
public class PeopleInvited implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected PeopleInvitedPK peopleInvitedPK;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 7)
    @Column(name = "answer")
    private String answer;
    @JoinColumn(name = "Id_usr", referencedColumnName = "Nickname", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private User user;
    @JoinColumn(name = "Id_e", referencedColumnName = "Id_e", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Event event;

    public PeopleInvited() {
    }

    public PeopleInvited(PeopleInvitedPK peopleInvitedPK) {
        this.peopleInvitedPK = peopleInvitedPK;
    }

    public PeopleInvited(PeopleInvitedPK peopleInvitedPK, String answer) {
        this.peopleInvitedPK = peopleInvitedPK;
        this.answer = answer;
    }

    public PeopleInvited(String idusr, int ide) {
        this.peopleInvitedPK = new PeopleInvitedPK(idusr, ide);
    }

    public PeopleInvitedPK getPeopleInvitedPK() {
        return peopleInvitedPK;
    }

    public void setPeopleInvitedPK(PeopleInvitedPK peopleInvitedPK) {
        this.peopleInvitedPK = peopleInvitedPK;
    }

    public String getAnswer() {
        return answer;
    }

    public void setAnswer(String answer) {
        this.answer = answer;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public Event getEvent() {
        return event;
    }

    public void setEvent(Event event) {
        this.event = event;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (peopleInvitedPK != null ? peopleInvitedPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof PeopleInvited)) {
            return false;
        }
        PeopleInvited other = (PeopleInvited) object;
        if ((this.peopleInvitedPK == null && other.peopleInvitedPK != null) || (this.peopleInvitedPK != null && !this.peopleInvitedPK.equals(other.peopleInvitedPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "it.polimi.wcalendar.business.security.PeopleInvited[ peopleInvitedPK=" + peopleInvitedPK + " ]";
    }
    
}
